#version 120

uniform mat4 modelworld;
uniform mat4 worldcamera;
uniform mat4 projection;
uniform vec3 lightposition; // in camera coordinates

varying vec3 normal, lightDir;

varying vec3 position;

void main()
{
	// transform normal to camera coordinates
	normal = (worldcamera * modelworld * vec4( gl_Normal, 0.0 ) ).xyz;
	//normal = vec3(0.0, 1.0, 0.0);
	//normal = (mat3(worldcamera) * mat3(modelworld) * normal).xyz;
	
	// transform vertex to camera coordinates
	vec3 vertex = vec3( worldcamera * modelworld * gl_Vertex );
	
	// calculate light direction
	//lightDir = vec3(lightposition - vertex );
	lightDir = vec3(0.0, 1.0, 0.0);
	lightDir = mat3(worldcamera) * mat3(modelworld) * lightDir;
	
	// get texture coordinate
	// gl_TexCoord[0]  = gl_MultiTexCoord0;
	gl_TexCoord[0] = vec4(8*(gl_Vertex.xz+vec2(1.0)), 0.0, 0.0);
	
	// project the point into the camera
	gl_Position = projection * vec4( vertex, 1.0 );
	
	position = gl_Vertex.xyz;
}
